package com.hui.tset01.util;

import lombok.Data;

import java.io.Serializable;

/**
 * 统一返回结果
 * @param <T>
 */
@Data
public class Result<T> implements Serializable {
    private Integer code;
    private String msg; //错误信息
    private T data; //数据

    //成功附带数据返回结果
    public static<T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(200);
        result.setData(data);
        return result;
    }
    //成功不附带数据返回结果
    public static<T> Result<T> success() {
        Result<T> result = new Result<>();
        result.setCode(200);
        return result;
    }
    //失败返回结果
    public static<T> Result<T> error(String msg) {
        Result<T> result = success();
        result.setMsg(msg);
        result.setCode(500);
        return result;
    }
}

